package com.ofc.chart.builder;

import com.ofc.chart.engine.IChartJsonBuilder;
import com.ofc.chart.model.Pie;

/**
 * Pie Chart Json对象构建类
 * 
 * @author zhangpeng
 * @date 2012-12-6
 */
public class PieJsonBuilder implements IChartJsonBuilder {
	private ElementBuilder elementBuilder = new ElementBuilder();
	private Pie pie;

	@Override
	public String buildJson() {
		StringBuffer json = new StringBuffer("{");
		String titleJson = elementBuilder.buildTitle(pie.getTitle());
		String xaxisJson = elementBuilder.buildXAxis(pie.getXaxis());
		String elementsJson = elementBuilder.buildElements(pie.getElements());
		if (titleJson != null && !"".equals(titleJson)) {
			json.append(titleJson + ",");
		}
		if (xaxisJson != null && !"".equals(xaxisJson)) {
			json.append(xaxisJson + ",");
		}
		json.append(elementsJson);
		json.append("}");
		return json.toString();
	}

	public PieJsonBuilder(Pie pie) {
		this.pie = pie;
	}
}
